home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 18 / CU Amiga Magazine's Super CD-ROM 18 (1997)(EMAP Images)(GB)[!][issue 1998-01].iso / CUCD / Online / hsc / docs-source / features / assign.hsc next >
Encoding:
Text File  |  1997-10-19  |  5.4 KB  |  177 lines

  1. <WEBPAGE chapter="hsc - " title="Attribute Assignments"
  2.     PREV="syntax.html"
  3.     NEXT="expressions.html">
  4.  
  5. When assigning new values to attributes, you can use string constants, like in html.
  6. Furthermore, you can also use expression to compute a new value depending on certain
  7. things. And there you can make the assignment of a value depend on the value of
  8. another attribute.
  9.  
  10. <H2>String Constants</H2>
  11.  
  12. As usual with html, you can use an assignment like
  13.  
  14. <$source pre><IMG SRC="hugo.gif" ALT='hugo'></$source>
  15.  
  16. to set the attribute <CODE>SRC</CODE> to <qqc>hugo.gif</qqc> and
  17. <CODE>ALT</CODE> to <qqc>hugo</qqc>. The first assignment uses double
  18. quotes to denote the string boundaries, the second one uses single
  19. quotes. There is no difference in the functionality between these to
  20. kinds of quotes.
  21.  
  22. <P>Again, like in html, one kind of quotes might show up inside a string,
  23. as long as it is quoted with other kind, for example:</P>
  24.  
  25. <$source pre><IMG SRC="quote.gif" ALT='"'></$source>
  26.  
  27. <P>Now <CODE>ALT</CODE> contains a double quote as value.</P>
  28.  
  29. <H2>Constants Without Quotes</H2>
  30.  
  31. If only certain characters are used, you even can omit the quotes at
  32. all. For example,
  33.  
  34. <$source pre><IMG SRC=hugo.gif ALT=hugo></$source>
  35.  
  36. is also legal. As this can cause problems with (very) old browsers, it
  37. might result in <ln_msg id="22">, if <hsc> is configured to. However,
  38. the following is not allowed according to the specifications of html:
  39.  
  40. <$source pre><IMG SRC=image/hugo.gif ALT=hugo></$source>
  41.  
  42. <P>Because of the <slash> in the value of <CODE>SRC</CODE>, it would
  43. have been required to put it inside quotes. As this is not the case,
  44. <ln_msg id="81"> will show up. Although most browsers can cope with
  45. this, and will use a white space or a <greater-than> as delimiter,
  46. this behavior is not standard.</P>
  47.  
  48. <H2><A NAME="cond-assign">Compute Expressions</A></H2>
  49.  
  50. <P>When the assigned value starts with a <bracket>, it denotes an
  51. expression to be computed before its result is used as new value.
  52. There are several operators you can use for that, and of course you
  53. also can refer to other attributes.</P>
  54.  
  55. A very basic example would be
  56.  
  57. <$source PRE><IMG SRC=(name+".gif") ALT=(name)></$source>
  58.  
  59. If the attribute <CODE>name</CODE> has been set to <qqc>sepp</qqc> before,
  60. this will result in
  61.  
  62. <$source PRE><IMG SRC="sepp.gif" ALT="sepp"></$source>
  63.  
  64. <P>The <qqc>+</qqc> is used to concatenate two values together.</P>
  65.  
  66. For more details on this, see the chapter about <ln-expression PLURAL>.
  67.  
  68. <H2>Conditional Assignments</H2>
  69.  
  70. <P>This paragraph deals with a feature you probably do not want to use
  71. (and understand) before you understood how those macros work. You can
  72. skip this part for now and return later.</P>
  73.  
  74. You can easily let an attribute obtain it's value from another
  75. attribute. For example, within a tag call you can use an assignment
  76. like
  77.  
  78. <PRE>sepp=(hugo)</PRE>
  79.  
  80. However, if <CODE>hugo</CODE> has not been defined and assigned a
  81. value before, this will result in an error message. Conditional
  82. assignments now only assign a value to the target attribute, if the
  83. source attribute has been set; in any case, the source attribute must
  84. have been defined before (using <TG>$macro</TG> or <TG>$define</TG>).
  85. Simply use a <qqc>?=</qqc> instead of the <qqc>=</qqc> assignment
  86. operator:
  87.  
  88. <PRE>sepp?=hugo</PRE>
  89.  
  90. This becomes handy for such macros which are more or less only
  91. extensions of real html-tags:
  92.  
  93. <$source PRE>
  94. <$macro MY-BODY BackGround:uri>
  95.     <BODY BackGround?=BackGround">
  96. </$macro>
  97. </$source>
  98.  
  99. <P>The macro <TG>MY-BODY</TG> just inserts a <TG>BODY</TG> tag. But
  100. optionally it can also handle the attribute
  101. <CODE>BackGround</CODE>.</P>
  102.  
  103. <P>But there has not necessarily a <CODE>BackGround</CODE> attribute to
  104. be set when calling <TG>MY-BODY</TG>. If you do not specify any,
  105. there also will not be one in the call to <TG>BODY</TG> after
  106. the macro has been processed.</P>
  107.  
  108. Two examples should point out this behavior:
  109.  
  110. <$source PRE><MY-BODY></$source>
  111.  
  112. will result in
  113.  
  114. <$source PRE><BODY></$source>
  115.  
  116. but a
  117.  
  118. <$source PRE><MY-BODY BackGround='image/backgr.png'></$source>
  119.  
  120. will lead to
  121.  
  122. <$source PRE><BODY BackGround="image/backgr.png"></$source>
  123.  
  124. thus in the second case also adding the attribute
  125. <CODE>BackGround</CODE> to the <TG>BODY</TG>-tag.
  126.  
  127. <P>If <TG>MY-BODY</TG> would have been declared without conditional
  128. assignment, it could have looked something like:
  129.  
  130. <$source PRE>
  131. <$macro MY-BODY BackGround:uri>
  132.     <BODY BackGround=(BackGround)>
  133. </$macro>
  134. </$source>
  135.  
  136. If you would try to call it without a <CODE>BackGround</CODE> passed,
  137. this attribute would have been unset, and the attempt to copy the
  138. value of <CODE>BackGround/MY-BODY</CODE> to
  139. <CODE>BackGround/BODY</CODE> using
  140. <CODE>BackGround=(BackGround)</CODE> would result in <ln_msg id="23">
  141.  
  142. <H2>Complex Conditions</H2>
  143.  
  144. <P>On the first sight, it might seem that there is only the simple
  145. condition <qq>if attribute is set..</qq> is possible. But no one
  146. prevents you from using code like this:
  147.  
  148. <$source PRE>
  149. <$define TEXT:color>
  150. <$if COND=(awfully complex condition))>
  151.     <$let TEXT='#123456'>
  152. </$if>
  153.  
  154. <MY-BODY TEXT?=TEXT>
  155. </$source>
  156.  
  157. This also works for <ln_let>:
  158.  
  159. <$source PRE>
  160. <$define sepp:string>
  161. <$define hugo:string>
  162.  
  163. <$if COND=(awfully complex condition)>
  164.     <$let hugo="hugo-value">
  165. </$if>
  166.  
  167. <$let sepp?=hugo>
  168. </$source>
  169.  
  170. and you can also use <ln-expression plural> to compute the source
  171. attribute. For instance, the last line of the above example also could
  172. have been
  173.  
  174. <$source PRE><$let sepp?=("hu"+"go")></$source>
  175.  
  176. </WEBPAGE>
  177.